package com.cinema;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import query.DataQuery;

import com.cinema.data.Adminusr;
import com.cinema.data.FilmInfo;
import com.cinema.data.Schedule;

public class GetTicket extends HttpServlet{

	/**
	 * 
	 */
	public GetTicket(){
		super();
	}
	
	private static final long serialVersionUID = 4010782057746594985L;
	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		doPost(req, resp);
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
		String url = null;
		int pageid = Integer.parseInt(request.getParameter("pageid"));
		switch(pageid){
		case 1:
			url = "/ticket.jsp";
			break;
		case 2:
			url = "/removefilm.jsp";
			break;
		default:
			url = "/admincp.html";
		}
		HttpSession s = request.getSession();
		Adminusr user = (Adminusr)s.getAttribute("adminuser");
		
		if(user == null)
			response.sendRedirect("admincp.html");
		else{
			if(user.getGroupid() != 1)//not admin
				url = "/ticket.jsp";
			DataQuery query = new DataQuery();
			List<FilmInfo> currentFilm = query.getCurrentFilmList();
			List<FilmInfo> comingFilm = query.getPlanFilmList();
			request.setAttribute("currentFilm", currentFilm);
			request.setAttribute("comingFilm", comingFilm);
			request.setAttribute("adminuser", user);
			RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher(url);
			try {
				dispatcher.forward(request, response);
			} catch (ServletException e) {
				e.printStackTrace();
			}
		}
	}
}